package com.sam;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.opensymphony.xwork2.ActionSupport;
import com.sam.entities.Cap;
import com.sam.utils.EMF;

public class ObtenerMarkers extends ActionSupport {

	private static final long serialVersionUID = 1150674425940678091L;
	
	private String idAdmisor;
	
	private List<Cap> caps;
	
	@SuppressWarnings("unchecked")
	public String execute() {
		
		EntityManager em = EMF.get().createEntityManager();
		Query query = em.createQuery("SELECT c FROM Cap c");
		setCaps((List<Cap>) query.getResultList());
		
		return SUCCESS;
	}

	public String getIdAdmisor() {
		return idAdmisor;
	}

	public void setIdAdmisor(String idAdmisor) {
		this.idAdmisor = idAdmisor;
	}


	public List<Cap> getCaps() {
		return caps;
	}

	public void setCaps(List<Cap> caps) {
		this.caps = caps;
	}
	
	public String foo (){
	EntityManager em = EMF.get().createEntityManager();
	try {
		em.persist(new Cap("BARRACAS", "Av. Montes de Oca 562",	-34.6349098, -58.3752727));
		em.persist(new Cap("BARRIO NORTE", "Av. Callao 1315",	-34.5936575, -58.3930047));		
		em.persist(new Cap("BELGRANO", "Juramento 2075", -34.5602302, -58.4536083));
		em.persist(new Cap("BELGRANO II", "Cabildo 800", -34.5699597, -58.4449182));
		
	} finally {
		em.close();
	}
	
	em = EMF.get().createEntityManager();
	try {
	em.persist(new Cap("CABALLITO", "Av. Rivadavia 5317", -34.620044, -58.4404609));
	em.persist(new Cap("CATALINAS NORTE", "Av. L. N. Alem 1002", -34.5961329, -58.3722977));
	em.persist(new Cap("DEVOTO", "Av. Francisco Beiró 3275", -34.5980718, -58.4992756));
	em.persist(new Cap("FLORES", "Av. Rivadavia 6668", -34.6278582, -58.4595133));
	} finally {
		em.close();
	}
	
	em = EMF.get().createEntityManager();
	try {
	em.persist(new Cap("LINIERS", "Av. Rivadavia 11060", -34.6390218, -58.5199937));
	em.persist(new Cap("MICROCENTRO", "Av. Corrientes 420", -34.6031884, -58.3727218));
	em.persist(new Cap("MICROCENTRO II", "Suipacha 658", -34.600624, -58.3796423));
	em.persist(new Cap("ONCE", "Av. Corrientes 2478", -34.6047236, -58.4018383));
	} finally {
		em.close();
	}
	em = EMF.get().createEntityManager();
	try {
	em.persist(new Cap("PALERMO", "Av. Santa Fe 3157", -34.5894667, -58.4095531));
	em.persist(new Cap("PARQUE PATRICIOS", "La Rioja 2193", -34.6370615, -58.4056421));
	em.persist(new Cap("PUERTO MADERO", "Juana Manso 1550", -34.6154857, -58.3619898));
	em.persist(new Cap("VILLA URQUIZA", "Av. Triunvirato 4458", -34.5760368, -58.4836545));	
	} finally {
		em.close();
	}
	
	return SUCCESS;
	}

//	
}
